<%-- 
    Document   : editStudent
    Created on : Dec 18, 2014, 3:23:04 PM
    Author     : nga
--%>

<%@page import="entity.Student"%>
<%@page import="dao.StudentDAO"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!doctype html>
<%!
    Connection con = null;
    PreparedStatement prst=null;
%>  
<%
    String msg = "";
    Student stu=StudentDAO.getStudent(request.getParameter("id"));
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    String xage = request.getParameter("age");
    int age=Integer.parseInt(xage);
    String address = request.getParameter("add");
    char gender = request.getParameter("gender").charAt(0);
    String batch = request.getParameter("batch");
    String image = request.getParameter("image");
    Student newStu=new Student(id,name,age,address,gender,batch,image);  
        if(request.getParameter("save")!=null){
            StudentDAO.edit(newStu);
            response.sendRedirect("listStudents.jsp");
        }         
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<h2>Edit Student</h2>
<p>
  <label for="textfield2">Name:</label>
  <input type="text" name="name" id="textfield2" value='<%=stu.getName()%>'>
  <label for="textfield3"><br>
    <br>
    Age
  :</label>
  <input type="text" name="age" id="textfield3" value='<%=stu.getAge()%>'>
</p>
<p>
  <label for="textfield4">Address:</label>
  <input type="text" name="add" id="textfield4" value='<%=stu.getAddress()%>'>
</p>
<p>
  <label for="textfield5">Gender:</label>
  <input type="text" name="gender" id="textfield5" value='<%=stu.getGender()%>'>
</p>
<p>
  <label for="textfield6">Batch:</label>
  <input type="text" name="batch" id="textfield6" value='<%=stu.getBatch()%>'>
</p>
<p>
  <label for="textfield7">Image:</label>
  <input type="text" name="image" id="textfield7" value='<%=stu.getImage()%>'>
</p>
<p>
            <input type='submit' name='save' id='save' value='Save'>
            <a href = 'listCategories.jsp'> <input type='button' name='cancel' id='cancel' value='Cancel'></a>
</p>
</body>
</html>